﻿<?xml version="1.0" encoding="utf-8"?>
<!--
        作者：          liuleyi
        更新时间：      20170227
        用途：          生成存储过程默认模板
-->
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="text" indent="no" encoding="utf-8" byte-order-mark="no"/>  
	<xsl:template match="/">

	<xsl:variable name="StringTypeDefine" select="document('../model/0101_StringTypeDefine.xml')"/>
	<xsl:variable name="EnumTypeDefine" select="document('../model/0102_EnumTypeDefine.xml')"/>
	<xsl:variable name="BooleanTypeDefine" select="document('../model/0103_BooleanTypeDefine.xml')"/>
	<xsl:variable name="DateTypeDefine" select="document('../model/0104_DateTypeDefine.xml')"/>
	<xsl:variable name="NumberTypeDefine" select="document('../model/0105_NumberTypeDefine.xml')"/>
	<xsl:variable name="IntegerTypeDefine" select="document('../model/0106_IntegerTypeDefine.xml')"/>
	<xsl:variable name="FuncConfig" select="document('../model/0801_AdminFunNoConfig.xml')"/>
<xsl:for-each select="Controllers/Controller">
<xsl:variable name="fileName" select="concat('./generate/php/Admin/Controller/',@code,'Controller.class.php')"/>
<xsl:result-document encoding="utf-8" method="text" href="{$fileName}">&lt;?php
/*
*作者:liuleyi
*功能描述:<xsl:value-of select="@label"/>
*修改记录
*修改时间   修改人     修改描述
*/
namespace Admin\Controller;
use Think\Controller;
class <xsl:value-of select="@code"/>Controller extends  Controller{
<xsl:variable name="ControllerName" select="@code"/>
<xsl:for-each select="add">
<xsl:variable name="func" select="@func"/>
    public function  add(){
        if (!empty($_POST)) {

            $func = new \Admin\Func\Func<xsl:value-of select="@func"/>(<xsl:for-each select="$FuncConfig//FunNo[@code=$func]"><xsl:for-each select="Request/Column">I(VAR_<xsl:value-of select="upper-case(@name)"/>)<xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:for-each>);

            if ($func->execute() === false) {
                $this->error("新增失败:" . $func->getErrMsg());
            } else {
                // $this->display();
                $this->success('新增成功！');
            }
            //  $this->display();
        } else {
            $this->display();
        }
    }
</xsl:for-each>
<xsl:for-each select="del">
<xsl:variable name="func" select="@func"/>
    public function  del(<xsl:for-each select="$FuncConfig//FunNo[@code=$func]"><xsl:for-each select="Request/Column">$<xsl:value-of select="@name"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:for-each>){
        $func = new \Admin\Func\Func<xsl:value-of select="@func"/>(<xsl:for-each select="$FuncConfig//FunNo[@code=$func]"><xsl:for-each select="Request/Column">$<xsl:value-of select="@name"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:for-each>);
        if ($func->execute() === false) {
            $this->error('删除失败' . $func->getErrMsg());
        } else {
            $this->redirect('<xsl:value-of select="$ControllerName"/>/lst');
        }
    }
</xsl:for-each>
<xsl:for-each select="edit">
<xsl:variable name="func" select="@func"/>
<xsl:variable name="pk" select="@pk"/>
    public function  edit(<xsl:for-each select="$FuncConfig//FunNo[@code=$pk]"><xsl:for-each select="Request/Column">$<xsl:value-of select="@name"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:for-each>){
        if (!empty($_POST)) {
            $func = new \Admin\Func\Func<xsl:value-of select="@func"/>(<xsl:for-each select="$FuncConfig//FunNo[@code=$func]"><xsl:for-each select="Request/Column">I(VAR_<xsl:value-of select="upper-case(@name)"/>)<xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:for-each>);
            if ($func->execute() === false) {
                $this->error("编辑失败:" . $func->getErrMsg());
            } else {
                $this->success('编辑成功！');
            }
        } else {

            $func = new \Admin\Func\Func<xsl:value-of select="@pk"/>(<xsl:for-each select="$FuncConfig//FunNo[@code=$pk]"><xsl:for-each select="Request/Column">$<xsl:value-of select="@name"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:for-each>);
            if ($func->execute() === false) {
                $this->error('查询失败:' . $func->getErrMsg());
            } else {
                $this->assign(POST, $func->getRst()[0]);
                $this->display();
            }
        }
    }
</xsl:for-each>
<xsl:for-each select="lst">
<xsl:variable name="func" select="@func"/>
    public function  lst(){
      $func = new \Admin\Func\Func<xsl:value-of select="@func"/>(<xsl:for-each select="$FuncConfig//FunNo[@code=$func]"><xsl:for-each select="Request/Column">I(VAR_<xsl:value-of select="upper-case(@name)"/>)<xsl:if test="position()!=last()">,</xsl:if></xsl:for-each></xsl:for-each>);
        if ($func->execute() === false) {
            $this->error('查询失败:' . $func->getErrMsg());
        } else {
            $location = new \Admin\Func\Func999010102(VAR_<xsl:value-of select="@func"/>);
            $location->execute();
            $this->assign(LOCATION, $location->getRst());
            $this->assign(GV_ENUM, $GLOBALS[GV_ENUM]);
            $this->assign(LST, $func->getRst());
        }
        $this->display();
    }
</xsl:for-each>
}
</xsl:result-document></xsl:for-each></xsl:template>  
</xsl:stylesheet>